﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ToolsLayer;
using BusinessEntity;
using Webcar.BLL;

namespace Webcar.Car
{
    public partial class RunRecordList : PageBase
    {
        protected string m_month
        {
            get { return Page.Request.QueryString["month"]; }
        }
        protected string m_dept_code
        {
            get { return Page.Request.QueryString["dept"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            GridViewStyler gvs = new GridViewStyler(this.GridView1);
            gvs.SetGridHover = false;
            gvs.SetStyle();
            if (this.IsPostBack)
                return;
            this.BindData();
        }

        private void BindData()
        {
            DEPTEntity d = DEPTEntityAction.RetrieveADEPTEntity(this.m_dept_code);
            this.Label1.Text = "当前是" + d.DEPT_NAME + this.m_month + "没有无功运行记录的车辆统计：";

            string procname = "prc_getRunRecordList_car";
            IDataParameter p = DB.helper.GetParameter("@month", this.m_month);
            IDataParameter p2 = DB.helper.GetParameter("@dept", this.m_dept_code);
            
            DataSet ds = DB.ExecuteProcedure(procname, p, p2);

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
            //sql = string.Format(sql, this.m_dept_code, this.m_month);
            /*
            this.WebPager1.ItemsPerPage = 15; //每页显示的记录条数。
            this.WebPager1.ControlToPaginate = "GridView1"; //与其关联需绑定的DataGrid或DataList控件ID。
            this.WebPager1.SelectCommand = sql;
            this.WebPager1.ConnectionString = DB.ConnectString;
            this.WebPager1.DataBind();
             * */
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex == -1)
                return;
            string car_no = this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
            HyperLink hl2 = (HyperLink)e.Row.FindControl("linkView");
            hl2.NavigateUrl = this.AddUrlQuery("~/Main.aspx?type=runrecord&query=", "query="+HttpUtility.UrlEncode("record_no=" + car_no));
        }
    }
}
